
/**
 * Save report name
 *
 * @param string $name report name
 */	
function savename(name)
{
   name = name.replace(/_/g,"+");
   SendValues( '/reports/saverow/reportname/'+name+'/');
}

/**
 * Dinamic create table
 *
 * @param string $id table row id
 * @param string $value table row value
 * @param string $table_name table name
 * @param int $column_index table column index
 * @param string $image_url url for images
 * @param string $static_table_id static table id
 */	

function create_table(id, value, table_name, column_index, image_url, static_table_id, language_constant)
{
	var sort_table_name ='';
    var type = 0;
    if (static_table_id=='sort1')
    {sort_table_name = 'orderbytable'; type =1}
    else if(static_table_id=='sort2')
    {sort_table_name = 'sortfieldstable'; type = 3}
    else if (static_table_id=='sort3')
    {sort_table_name = 'groupbytable';type = 2}
	
    var exist_row = false;	
    var table = document.getElementById(static_table_id);
    tblBody = table.tBodies[0];
    var rows = table.getElementsByTagName("tr");
    for(i = 0; i < rows.length; i++)
    if (rows[i].id == id)
    {
  	  exist_row = true;
      if(value == '-'||value == false)
       {
	    	SendValues( '/reports/deleterow/'+rows[i].rowIndex+'/'+value+'/'+type);
	    	tblBody.removeChild(rows[i]);
	   }
      else
       {
       		rows[i].cells[2].innerHTML = value;
      	    row_ = rows[i];
       }
    
    }
  
 if(value!='-'&&value != false)
  {
 	if(exist_row==false)
    { 
	  	var row = document.createElement("tr");
	    row.id = id;
	    var cell_1 = document.createElement("td");
	    var cell_2 = document.createElement("td");
	    var cell_3 = document.createElement("td");
	    var cellText_1 = document.createTextNode(id);
	    if(value)
	    var cellText_2 = document.createTextNode(value);

	    //-- 
	    var button_down = document.createElement("input");
	    button_down.type = 'button';
	    button_down.style.background = "url("+image_url+"arrow_down.gif) no-repeat";
	    button_down.style.border = '0';
	    button_down.style.padding = '0';
	    button_down.style.width = 11;
	    button_down.style.height = 8;
	    button_down.setAttribute('onClick', 'move_sort_table_row( this.parentNode.parentNode, 1 ,\''+sort_table_name+'\' )');
	    button_down.onclick = function() {move_sort_table_row( this.parentNode.parentNode , 1 ,sort_table_name)};
	
	    //--
	    var button_up = document.createElement("input");
	    button_up.type = 'button';
	    button_up.style.background = "url("+image_url+"arrow_up.gif) no-repeat";
	    button_up.style.background.repeat = 'no-repeat';
	    button_up.style.border = '0';
	    button_up.style.padding = '0';
	    button_up.style.width = 11;
	    button_up.style.height = 8;
	    button_up.setAttribute('onClick', 'move_sort_table_row( this.parentNode.parentNode, -1  ,\''+sort_table_name+'\')');
	    button_up.onclick = function() {move_sort_table_row( this.parentNode.parentNode , -1 ,sort_table_name)};
	    //--
	
	    cell_1.width = 15;
	    cell_2.width = 150;
	    cell_1.appendChild(button_up);
	    cell_1.appendChild(button_down);
	    cell_2.appendChild(cellText_1);
	    cell_3.appendChild(cellText_2);
	    
	    row.appendChild(cell_1);
	    row.appendChild(cell_2);
	    if(value!=true)
	    row.appendChild(cell_3);
	    tblBody.appendChild(row);
	    table.appendChild(tblBody);
	    row_ = row;
    }
   id_ = id.replace(/_/g,"+");
   if(language_constant!=null)
   {
   	language_constant = language_constant.replace(/ /g,"_");
    language_constant = language_constant.replace(/_/g,"+");
   }
   else
   language_constant = '';
   SendValues( '/reports/saverow/'+row_.rowIndex+'/'+id_+'/'+value+'/'+table_name+'/'+column_index+'/'+type+'/'+language_constant);
  }
  
  if(rows.length == 1)
  	table.style.display='none';
  else
  	table.style.display='';

  
}

/**
 * Move table row
 *
 * @param object table row $row
 * @param integer $move moving derection
 * @param string $table_name table name
 */	
function move_sort_table_row(row,move,table_name)
{
	if(row.rowIndex+move>0)
	{
		moverow(row,move);
		var length = row.parentNode.rows.length;
		if (length>1)
		{
			var k = parseInt(row.rowIndex)+move;
			if(k>=0 && k<=(length-1))
		    {
		    	SendValues( '/reports/moverow/'+row.rowIndex+'/'+k+'/'+table_name);
		    }
		}  
	}
}